﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using DTO;
using BUS;

namespace NGU.WUC
{
    public partial class logged_box : System.Web.UI.UserControl
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Session["ID"] != null)
            {               
                KhachHangBUS bus = new KhachHangBUS();
                try
                {
                    KhachHangDTO kh = bus.layThongTinKhachHangTheoMaTK(Session["ID"].ToString());
                    if (kh == null)
                    {
                        this.user.InnerText = Session["Username"].ToString().ToLower();
                        this.registerDate.InnerText = "Chưa có thông tin";
                    }
                    else
                    {
                        this.user.InnerText = kh.HoTen;
                        this.registerDate.InnerHtml = String.Format("{0:dd/MM/yyyy}", kh.NgayDangKy);
                    }
                }
                catch (Exception ex)
                {
                    Response.Redirect("InfoPage.aspx");
                }
            }
        }

        protected void logoutBut_Click(object sender, EventArgs e)
        {
            Session.RemoveAll();
            HttpCookie cookie = new HttpCookie("remember", "yes");
            cookie.Expires = DateTime.Now.AddDays(-1);
            Response.Cookies.Add(cookie);
            cookie = new HttpCookie("unpw");
            cookie.Expires = DateTime.Now.AddDays(-1);
            Response.Cookies.Add(cookie);
            Response.Redirect(Request.RawUrl);
        }
    }
}